package com.kucai.yifaqapp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.kucai.yifaqapp.R;
import com.kucai.yifaqapp.global.HttpAdress;
import com.kucai.yifaqapp.model.CustomObserver;
import com.kucai.yifaqapp.model.network.HttpJsonUtils;
import com.kucai.yifaqapp.model.network.entity.res.Pay_CurrentTimeBean;
import com.kucai.yifaqapp.model.network.entity.res.z_weixin_ty;
import com.kucai.yifaqapp.util.SYSOUtils;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;


/**
 * Created by admin on 2018/12/4.
 */

public class Z_weixinctivity2 extends BaseActivitySimple {
    EditText zz001;
    TextView zz002;
    EditText zz003;
    TextView zz004;
    Button zz005;
    String remark;
    RelativeLayout back;
    LinearLayout skinbg;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.z_weixin2);
        back = findViewById(R.id.back);
        skinbg=findViewById(R.id.skinbg);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        try {
            initView();
            initData();
        } catch (Exception e) {

        }
    }

    private void initView() {
        zz001 = findViewById(R.id.zz001);
        zz002 = findViewById(R.id.zz002);
        zz003 = findViewById(R.id.zz003);
        zz004 = findViewById(R.id.zz004);
        zz005 = findViewById(R.id.zz005);
        zz002.setText("单笔下限" + z_weixin_ty.min + "单笔上限" + z_weixin_ty.max);
    }

    @Override
    protected int setContentView() {
        return R.layout.z_weixin2;
    }

    @Override
    protected void ChangeSkin() {
        switch (SkinId) {
            case 17771:
                skinbg.setBackgroundResource(R.mipmap.skin_bg1);
                break;
            case 17772:
                skinbg.setBackgroundResource(R.mipmap.skin_bg2);
                break;
            case 17773:
                skinbg.setBackgroundResource(R.mipmap.skin_bg3);
                break;
            default:
                skinbg.setBackgroundResource(R.mipmap.skin_bg1);
        }
    }

    private void initData() {
        zz005.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (zz001.getText().toString().isEmpty()) {
                    Toast.makeText(Z_weixinctivity2.this, "请输入金额", Toast.LENGTH_SHORT).show();
                    return;
                }
                if(Double.parseDouble(zz001.getText().toString())<Integer.parseInt(z_weixin_ty.min)){
                    Toast.makeText(Z_weixinctivity2.this, "输入金额不能小于"+z_weixin_ty.min, Toast.LENGTH_SHORT).show();
                    return;
                }
                if(Double.parseDouble(zz001.getText().toString())>Integer.parseInt(z_weixin_ty.max)){
                    Toast.makeText(Z_weixinctivity2.this, "输入金额不能大于"+z_weixin_ty.max, Toast.LENGTH_SHORT).show();
                    return;
                }

                if (zz003.getText().toString().isEmpty()) {
                    Toast.makeText(Z_weixinctivity2.this, "请输入转账人姓名", Toast.LENGTH_SHORT).show();
                    return;
                }
                z_weixin_ty.realName = zz003.getText().toString().trim();
                z_weixin_ty.rechMoney = zz001.getText().toString().trim();
                Intent intent = new Intent(Z_weixinctivity2.this, Z_weixinctivity3.class);
                startActivity(intent);
                finish();
            }
        });
        //获取当前服务器时间
        HttpJsonUtils.getHttpApiInstance()
                .getTime(HttpAdress.getuseAdress() + "api/m/get/date")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Pay_CurrentTimeBean>(this) {
                    @Override
                    protected void onCustomNext(Pay_CurrentTimeBean resBanner) {
                        try {
                            if(resBanner.getCode()==0){
                                zz004.setText(resBanner.getData() + "");
                                z_weixin_ty.rechTime = resBanner.getData() + "";
                            }else {
                                Toast.makeText(Z_weixinctivity2.this,resBanner.getMsg(),Toast.LENGTH_SHORT).show();
                            }
                        }catch (Exception e){
                            Toast.makeText(Z_weixinctivity2.this,"异常错误，请重新操作",Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                        SYSOUtils.sOut(e.toString());
                    }
                });
    }
}
